package com.qf.hytrix.service;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.qf.service.Book;

import java.util.List;

/**
 * @Auther: Song
 * @Date: 2022-03-19 15:07
 */
public class BookBatchCommand extends HystrixCommand<List<Book>> {
    private List<Integer> ids;

    private BookService2 bookService2;

    protected BookBatchCommand(List<Integer> ids,BookService2 bookService2) {
        super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("batchCmd")).andCommandKey(HystrixCommandKey.Factory.asKey("batchKey")));
        this.ids = ids;
        this.bookService2 = bookService2;
    }


    @Override
    protected List<Book> run() throws Exception {
        return bookService2.getBooksByIds(ids);
    }

    @Override
    protected List<Book> getFallback() {
        return null;
    }
}
